/* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details. */ 
package de.rockon.fuzzy.controller.gui.logger;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

import de.rockon.fuzzy.controller.util.Logger;
import de.rockon.fuzzy.controller.util.factories.IconFactory;

/**
 * Rendert die einzelnen Statusnachrichten
 * 
 */
public class LogMessageRenderer extends DefaultListCellRenderer {
	private static final long serialVersionUID = -4636231583415513849L;

	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

		setBackground(Color.WHITE);

		if (value == null) {
			setText(" ");
			setIcon(null);
			return this;
		}

		if (value.toString().startsWith("[INFO]")) {
			setIcon(IconFactory.getInstance().getImageIcon(IconFactory.ICON_INFO));
			setText(index + 1 + ": " + value.toString().substring(Logger.INFO.length()));
		}
		if (value.toString().startsWith("[ERROR]")) {
			setIcon(IconFactory.getInstance().getImageIcon(IconFactory.ICON_ERROR));
			setText(index + 1 + ": " + value.toString().substring(Logger.ERROR.length()));
		}
		if (value.toString().startsWith("[DEBUG]")) {
			setIcon(IconFactory.getInstance().getImageIcon(IconFactory.ICON_DEBUG));
			setText(index + 1 + ": " + value.toString().substring(Logger.DEBUG.length()));
		}

		if (cellHasFocus || isSelected) {
			setForeground(Color.blue);
		} else {
			setForeground(Color.black);
		}

		return this;
	}
}
